/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cognitivetouch.colorSpan;

/**
 *
 * @author Xiaoxing
 */
public class TrialTimer {

    long trialStart;

    public enum TaskProcess {

        Fix, Cue, Delay, Rule, Response, Feedback, ITI, Finished, Error;
    }

    public void tagTrialStart() {
        trialStart = System.nanoTime();
    }

    public TaskProcess getCurrentTask() {
        long currentTime = System.nanoTime();
        long timeProceeding = (currentTime - trialStart) / 1000000;
        if (timeProceeding < 0) {
            return TaskProcess.Error;
        } else if (timeProceeding < 2000) {
            return TaskProcess.Fix;
        } else if (timeProceeding < 4000) {
            return TaskProcess.Cue;
        } else if (timeProceeding < 8000) {
            return TaskProcess.Response;
        } else if (timeProceeding < 10000) {
            return TaskProcess.Feedback;
        } else if (timeProceeding < 12000) {
            return TaskProcess.ITI;
        } else if (timeProceeding >= 14000) {
            return TaskProcess.Finished;
        }
        return TaskProcess.Error;
    }
}
